import setting from '@/setting.js'
// 价格过滤
function handleFilterPrice(price = null) {
	if (!/^[0-9]+$/.test(price)) {
		console.log('"' + price + '"不是正整数');
		return price;
	}

	let new_price = 0;

	new_price = Number(price) / 100;

	return new_price;
};

// 配送时间处理
function handleFilterSendTime(sendTime, time) {
	let sendTime_a = Number(sendTime) * 60 * 1000; // 配送时间(分) 时间戳
	
	let timeDate = time * 1000;
	
	let sendTimeDate = new Date(Number(sendTime_a)+Number(timeDate));
	
	var hour = sendTimeDate.getHours();//得到小时
	var minu = sendTimeDate.getMinutes();//得到分钟
	
	if(hour < 10) {
		hour = "0"+hour;
	}
	
	if(minu < 10) {
		minu = "0"+minu;
	}
	
	return hour+":"+minu;
};

const $filter = {
	price: handleFilterPrice,
	sendTime: handleFilterSendTime,
}

const install = Vue => {
	Vue.filter('filterPrice', (data) => {
		return handleFilterPrice(data)
	})

	Vue.prototype.$filter = $filter
}

export default {
	install
}
